\hypertarget{a00049}{}\section{E\+:/knet-\/git/knet/knet/buffer.c 文件参考}
\label{a00049}\index{E\+:/knet-\/git/knet/knet/buffer.\+c@{E\+:/knet-\/git/knet/knet/buffer.\+c}}
{\ttfamily \#include \char`\"{}buffer.\+h\char`\"{}}\\*
\subsection*{结构体}
\begin{DoxyCompactItemize}
\item 
struct \hyperlink{a00003}{\+\_\+buffer\+\_\+t}
\end{DoxyCompactItemize}
\subsection*{函数}
\begin{DoxyCompactItemize}
\item 
\hyperlink{a00056_a4b09a7574cd440f9b94285ab73c81b4e_a4b09a7574cd440f9b94285ab73c81b4e}{kbuffer\+\_\+t} $\ast$ \hyperlink{a00049_ab7c640d7d31868f39679942dafd12175_ab7c640d7d31868f39679942dafd12175}{knet\+\_\+buffer\+\_\+create} (uint32\+\_\+t size)
\begin{DoxyCompactList}\small\item\em 创建一个固定长度的缓冲区 \end{DoxyCompactList}\item 
void \hyperlink{a00049_ad7934fdee7f0eea3f1581b5dd94736e2_ad7934fdee7f0eea3f1581b5dd94736e2}{knet\+\_\+buffer\+\_\+destroy} (\hyperlink{a00056_a4b09a7574cd440f9b94285ab73c81b4e_a4b09a7574cd440f9b94285ab73c81b4e}{kbuffer\+\_\+t} $\ast$sb)
\begin{DoxyCompactList}\small\item\em 销毁缓冲区 \end{DoxyCompactList}\item 
uint32\+\_\+t \hyperlink{a00049_abf453d69e41199e1f64314d31ff23a69_abf453d69e41199e1f64314d31ff23a69}{knet\+\_\+buffer\+\_\+put} (\hyperlink{a00056_a4b09a7574cd440f9b94285ab73c81b4e_a4b09a7574cd440f9b94285ab73c81b4e}{kbuffer\+\_\+t} $\ast$sb, const char $\ast$temp, uint32\+\_\+t size)
\begin{DoxyCompactList}\small\item\em 写入 \end{DoxyCompactList}\item 
uint32\+\_\+t \hyperlink{a00049_a8d22cd2f8625aee29cbf263e0fba8cef_a8d22cd2f8625aee29cbf263e0fba8cef}{knet\+\_\+buffer\+\_\+get\+\_\+length} (\hyperlink{a00056_a4b09a7574cd440f9b94285ab73c81b4e_a4b09a7574cd440f9b94285ab73c81b4e}{kbuffer\+\_\+t} $\ast$sb)
\begin{DoxyCompactList}\small\item\em 取得缓冲区内数据长度 \end{DoxyCompactList}\item 
uint32\+\_\+t \hyperlink{a00049_a8eee118becbc822b85b0459ece43b944_a8eee118becbc822b85b0459ece43b944}{knet\+\_\+buffer\+\_\+get\+\_\+max\+\_\+size} (\hyperlink{a00056_a4b09a7574cd440f9b94285ab73c81b4e_a4b09a7574cd440f9b94285ab73c81b4e}{kbuffer\+\_\+t} $\ast$sb)
\begin{DoxyCompactList}\small\item\em 取得缓冲区内最大长度 \end{DoxyCompactList}\item 
int \hyperlink{a00049_ab52a4b25cb665848167e2e3a57ad38f4_ab52a4b25cb665848167e2e3a57ad38f4}{knet\+\_\+buffer\+\_\+enough} (\hyperlink{a00056_a4b09a7574cd440f9b94285ab73c81b4e_a4b09a7574cd440f9b94285ab73c81b4e}{kbuffer\+\_\+t} $\ast$sb, uint32\+\_\+t size)
\begin{DoxyCompactList}\small\item\em 测试缓冲区内是否有足够空间 \end{DoxyCompactList}\item 
char $\ast$ \hyperlink{a00049_aad25b6a27ca6270b4cffb9c45daea697_aad25b6a27ca6270b4cffb9c45daea697}{knet\+\_\+buffer\+\_\+get\+\_\+ptr} (\hyperlink{a00056_a4b09a7574cd440f9b94285ab73c81b4e_a4b09a7574cd440f9b94285ab73c81b4e}{kbuffer\+\_\+t} $\ast$sb)
\begin{DoxyCompactList}\small\item\em 取得缓冲区数据起始地址 \end{DoxyCompactList}\item 
void \hyperlink{a00049_ace8a684108f818eab5d956235b0bce77_ace8a684108f818eab5d956235b0bce77}{knet\+\_\+buffer\+\_\+adjust} (\hyperlink{a00056_a4b09a7574cd440f9b94285ab73c81b4e_a4b09a7574cd440f9b94285ab73c81b4e}{kbuffer\+\_\+t} $\ast$sb, uint32\+\_\+t gap)
\begin{DoxyCompactList}\small\item\em 调整数据起始地址 \end{DoxyCompactList}\item 
void \hyperlink{a00049_ac787e1b4f944728f621d7f59b67eb0aa_ac787e1b4f944728f621d7f59b67eb0aa}{knet\+\_\+buffer\+\_\+clear} (\hyperlink{a00056_a4b09a7574cd440f9b94285ab73c81b4e_a4b09a7574cd440f9b94285ab73c81b4e}{kbuffer\+\_\+t} $\ast$sb)
\begin{DoxyCompactList}\small\item\em 清空缓冲区 \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{函数说明}
\hypertarget{a00049_ace8a684108f818eab5d956235b0bce77_ace8a684108f818eab5d956235b0bce77}{}\index{buffer.\+c@{buffer.\+c}!knet\+\_\+buffer\+\_\+adjust@{knet\+\_\+buffer\+\_\+adjust}}
\index{knet\+\_\+buffer\+\_\+adjust@{knet\+\_\+buffer\+\_\+adjust}!buffer.\+c@{buffer.\+c}}
\subsubsection[{knet\+\_\+buffer\+\_\+adjust}]{\setlength{\rightskip}{0pt plus 5cm}void knet\+\_\+buffer\+\_\+adjust (
\begin{DoxyParamCaption}
\item[{{\bf kbuffer\+\_\+t} $\ast$}]{sb, }
\item[{uint32\+\_\+t}]{gap}
\end{DoxyParamCaption}
)}\label{a00049_ace8a684108f818eab5d956235b0bce77_ace8a684108f818eab5d956235b0bce77}


调整数据起始地址 


\begin{DoxyParams}{参数}
{\em sb} & kbuffer\+\_\+t实例 \\
\hline
{\em gap} & 调整的长度 \\
\hline
\end{DoxyParams}
\hypertarget{a00049_ac787e1b4f944728f621d7f59b67eb0aa_ac787e1b4f944728f621d7f59b67eb0aa}{}\index{buffer.\+c@{buffer.\+c}!knet\+\_\+buffer\+\_\+clear@{knet\+\_\+buffer\+\_\+clear}}
\index{knet\+\_\+buffer\+\_\+clear@{knet\+\_\+buffer\+\_\+clear}!buffer.\+c@{buffer.\+c}}
\subsubsection[{knet\+\_\+buffer\+\_\+clear}]{\setlength{\rightskip}{0pt plus 5cm}void knet\+\_\+buffer\+\_\+clear (
\begin{DoxyParamCaption}
\item[{{\bf kbuffer\+\_\+t} $\ast$}]{sb}
\end{DoxyParamCaption}
)}\label{a00049_ac787e1b4f944728f621d7f59b67eb0aa_ac787e1b4f944728f621d7f59b67eb0aa}


清空缓冲区 


\begin{DoxyParams}{参数}
{\em sb} & kbuffer\+\_\+t实例 \\
\hline
\end{DoxyParams}
\hypertarget{a00049_ab7c640d7d31868f39679942dafd12175_ab7c640d7d31868f39679942dafd12175}{}\index{buffer.\+c@{buffer.\+c}!knet\+\_\+buffer\+\_\+create@{knet\+\_\+buffer\+\_\+create}}
\index{knet\+\_\+buffer\+\_\+create@{knet\+\_\+buffer\+\_\+create}!buffer.\+c@{buffer.\+c}}
\subsubsection[{knet\+\_\+buffer\+\_\+create}]{\setlength{\rightskip}{0pt plus 5cm}{\bf kbuffer\+\_\+t}$\ast$ knet\+\_\+buffer\+\_\+create (
\begin{DoxyParamCaption}
\item[{uint32\+\_\+t}]{size}
\end{DoxyParamCaption}
)}\label{a00049_ab7c640d7d31868f39679942dafd12175_ab7c640d7d31868f39679942dafd12175}


创建一个固定长度的缓冲区 


\begin{DoxyParams}{参数}
{\em size} & 缓冲区长度（字节） \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
kbuffer\+\_\+t实例 
\end{DoxyReturn}
\hypertarget{a00049_ad7934fdee7f0eea3f1581b5dd94736e2_ad7934fdee7f0eea3f1581b5dd94736e2}{}\index{buffer.\+c@{buffer.\+c}!knet\+\_\+buffer\+\_\+destroy@{knet\+\_\+buffer\+\_\+destroy}}
\index{knet\+\_\+buffer\+\_\+destroy@{knet\+\_\+buffer\+\_\+destroy}!buffer.\+c@{buffer.\+c}}
\subsubsection[{knet\+\_\+buffer\+\_\+destroy}]{\setlength{\rightskip}{0pt plus 5cm}void knet\+\_\+buffer\+\_\+destroy (
\begin{DoxyParamCaption}
\item[{{\bf kbuffer\+\_\+t} $\ast$}]{sb}
\end{DoxyParamCaption}
)}\label{a00049_ad7934fdee7f0eea3f1581b5dd94736e2_ad7934fdee7f0eea3f1581b5dd94736e2}


销毁缓冲区 


\begin{DoxyParams}{参数}
{\em sb} & kbuffer\+\_\+t实例 \\
\hline
\end{DoxyParams}
\hypertarget{a00049_ab52a4b25cb665848167e2e3a57ad38f4_ab52a4b25cb665848167e2e3a57ad38f4}{}\index{buffer.\+c@{buffer.\+c}!knet\+\_\+buffer\+\_\+enough@{knet\+\_\+buffer\+\_\+enough}}
\index{knet\+\_\+buffer\+\_\+enough@{knet\+\_\+buffer\+\_\+enough}!buffer.\+c@{buffer.\+c}}
\subsubsection[{knet\+\_\+buffer\+\_\+enough}]{\setlength{\rightskip}{0pt plus 5cm}int knet\+\_\+buffer\+\_\+enough (
\begin{DoxyParamCaption}
\item[{{\bf kbuffer\+\_\+t} $\ast$}]{sb, }
\item[{uint32\+\_\+t}]{size}
\end{DoxyParamCaption}
)}\label{a00049_ab52a4b25cb665848167e2e3a57ad38f4_ab52a4b25cb665848167e2e3a57ad38f4}


测试缓冲区内是否有足够空间 


\begin{DoxyParams}{参数}
{\em sb} & kbuffer\+\_\+t实例 \\
\hline
{\em size} & 需求长度 \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em 0} & 没有足够空间 \\
\hline
{\em 非零} & 有足够空间 \\
\hline
\end{DoxyRetVals}
\hypertarget{a00049_a8d22cd2f8625aee29cbf263e0fba8cef_a8d22cd2f8625aee29cbf263e0fba8cef}{}\index{buffer.\+c@{buffer.\+c}!knet\+\_\+buffer\+\_\+get\+\_\+length@{knet\+\_\+buffer\+\_\+get\+\_\+length}}
\index{knet\+\_\+buffer\+\_\+get\+\_\+length@{knet\+\_\+buffer\+\_\+get\+\_\+length}!buffer.\+c@{buffer.\+c}}
\subsubsection[{knet\+\_\+buffer\+\_\+get\+\_\+length}]{\setlength{\rightskip}{0pt plus 5cm}uint32\+\_\+t knet\+\_\+buffer\+\_\+get\+\_\+length (
\begin{DoxyParamCaption}
\item[{{\bf kbuffer\+\_\+t} $\ast$}]{sb}
\end{DoxyParamCaption}
)}\label{a00049_a8d22cd2f8625aee29cbf263e0fba8cef_a8d22cd2f8625aee29cbf263e0fba8cef}


取得缓冲区内数据长度 


\begin{DoxyParams}{参数}
{\em sb} & kbuffer\+\_\+t实例 \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
数据长度 
\end{DoxyReturn}
\hypertarget{a00049_a8eee118becbc822b85b0459ece43b944_a8eee118becbc822b85b0459ece43b944}{}\index{buffer.\+c@{buffer.\+c}!knet\+\_\+buffer\+\_\+get\+\_\+max\+\_\+size@{knet\+\_\+buffer\+\_\+get\+\_\+max\+\_\+size}}
\index{knet\+\_\+buffer\+\_\+get\+\_\+max\+\_\+size@{knet\+\_\+buffer\+\_\+get\+\_\+max\+\_\+size}!buffer.\+c@{buffer.\+c}}
\subsubsection[{knet\+\_\+buffer\+\_\+get\+\_\+max\+\_\+size}]{\setlength{\rightskip}{0pt plus 5cm}uint32\+\_\+t knet\+\_\+buffer\+\_\+get\+\_\+max\+\_\+size (
\begin{DoxyParamCaption}
\item[{{\bf kbuffer\+\_\+t} $\ast$}]{sb}
\end{DoxyParamCaption}
)}\label{a00049_a8eee118becbc822b85b0459ece43b944_a8eee118becbc822b85b0459ece43b944}


取得缓冲区内最大长度 


\begin{DoxyParams}{参数}
{\em sb} & kbuffer\+\_\+t实例 \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
最大长度 
\end{DoxyReturn}
\hypertarget{a00049_aad25b6a27ca6270b4cffb9c45daea697_aad25b6a27ca6270b4cffb9c45daea697}{}\index{buffer.\+c@{buffer.\+c}!knet\+\_\+buffer\+\_\+get\+\_\+ptr@{knet\+\_\+buffer\+\_\+get\+\_\+ptr}}
\index{knet\+\_\+buffer\+\_\+get\+\_\+ptr@{knet\+\_\+buffer\+\_\+get\+\_\+ptr}!buffer.\+c@{buffer.\+c}}
\subsubsection[{knet\+\_\+buffer\+\_\+get\+\_\+ptr}]{\setlength{\rightskip}{0pt plus 5cm}char$\ast$ knet\+\_\+buffer\+\_\+get\+\_\+ptr (
\begin{DoxyParamCaption}
\item[{{\bf kbuffer\+\_\+t} $\ast$}]{sb}
\end{DoxyParamCaption}
)}\label{a00049_aad25b6a27ca6270b4cffb9c45daea697_aad25b6a27ca6270b4cffb9c45daea697}


取得缓冲区数据起始地址 


\begin{DoxyParams}{参数}
{\em sb} & kbuffer\+\_\+t实例 \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
数据长度 
\end{DoxyReturn}
\hypertarget{a00049_abf453d69e41199e1f64314d31ff23a69_abf453d69e41199e1f64314d31ff23a69}{}\index{buffer.\+c@{buffer.\+c}!knet\+\_\+buffer\+\_\+put@{knet\+\_\+buffer\+\_\+put}}
\index{knet\+\_\+buffer\+\_\+put@{knet\+\_\+buffer\+\_\+put}!buffer.\+c@{buffer.\+c}}
\subsubsection[{knet\+\_\+buffer\+\_\+put}]{\setlength{\rightskip}{0pt plus 5cm}uint32\+\_\+t knet\+\_\+buffer\+\_\+put (
\begin{DoxyParamCaption}
\item[{{\bf kbuffer\+\_\+t} $\ast$}]{sb, }
\item[{const char $\ast$}]{temp, }
\item[{uint32\+\_\+t}]{size}
\end{DoxyParamCaption}
)}\label{a00049_abf453d69e41199e1f64314d31ff23a69_abf453d69e41199e1f64314d31ff23a69}


写入 


\begin{DoxyParams}{参数}
{\em sb} & kbuffer\+\_\+t实例 \\
\hline
{\em temp} & 字节数组指针 \\
\hline
{\em size} & 字节数组长度 \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em 0} & 写入失败 \\
\hline
{\em $>$0} & 实际写入的字节数 \\
\hline
\end{DoxyRetVals}
